package cn.dduan.fool.utils.date;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateUtils {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        // DateUtils.testTimestamp();
        DateUtils.timestampToDate("1733915520.0000");
        DateUtils.timestampToDate("0.0000");
        DateUtils.timestampToDate("946688448.0000");
        DateUtils.timestampToDate("");

    }

    /**
     * 时间戳转时间
     *
     * @author dduan
     * @version 1.0
     * @date 2025/4/8
     */
    private static void timestampToDate(String t) {
        long timestamp = (long) Double.parseDouble(t) * 1000;
        System.out.println("时间：" + simpleDateFormat.format(timestamp));
    }

    /**
     * 字符串时间戳转日期
     *
     * @author dduan
     * @version 1.0
     * @date 2025/4/8
     */
    private static void testTimestamp() {
        String transmissionTime = "2025-03-01 22:42:02";
        System.out.println("原时间：" + transmissionTime);
        try {
            Date date1 = sdf.parse(transmissionTime);
            System.out.println(date1);
        } catch (ParseException e) {
            System.out.println("zhuanhuanyichang");
        }
    }
}
